<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>后台管理页面</title>
    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        header .col-md-3{background-color: #3a4144}
        header .col-md-9{background-color: #282d2f}
        header>div>div{height: 50px}
        section .col-md-3{
            background-color: #282d2f;
            padding: 100px 50px;
        }
        section .col-md-9{
            background-color: #3a4144;
        }
        section>div>div{height: 1000px}
        /*左侧边栏相关样式*/
        .panel-default,.panel-default>.panel-heading{
            background-color: rgba(0,0,0,0);
            border: 0;
            color: #eee;
        }

    </style>
</head>
<body>
<header>
    <div class="row">
        <div class="col-md-3">
            <a href="/">
                <img src="/images/logo.png" alt="">
            </a>
        </div>
        <div class="col-md-9">
            <span style="float: right;font-size: 20px;line-height: 50px">
                <span style="color: #eee">{{user.nick}}欢迎你</span>
                <a href="#" @click="logout()">退出登录</a>
            </span>
        </div>
    </div>
</header>
<section>
<div class="row">
    <div class="col-md-3">
        <!--折叠插件开始-->
        <div class="panel-group" id="accordion">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion"
                           href="#collapseOne">
                            分类管理
                        </a>
                    </h4>
                </div>
                <div id="collapseOne" class="panel-collapse collapse in">
                    <div class="panel-body">
                        <ul style="list-style-type: none">
                            <li><a href="">分类列表</a></li>
                            <li><a href="#" @click="add()">添加分类</a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion"
                           href="#collapseTwo">
                            作品管理
                        </a>
                    </h4>
                </div>
                <div id="collapseTwo" class="panel-collapse collapse">
                    <div class="panel-body">
                        <ul style="list-style-type: none">
                            <li><a href="/admin-product.html">作品列表</a></li>
                            <li><a href="/send.html">添加作品</a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion"
                           href="#collapseThree">
                            轮播图管理
                        </a>
                    </h4>
                </div>
                <div id="collapseThree" class="panel-collapse collapse">
                    <div class="panel-body">
                        <ul style="list-style-type: none">
                            <li><a href="/admin-banner.html">轮播图列表</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <!--折叠插件结束-->
    </div>
    <div class="col-md-9" style="color: #eee">
        <h2>欢迎访问VRD后台管理系统</h2>
        <table border="1" style="width: 70%;text-align: center">
            <caption>分类列表</caption>
            <tr>
                <th>序号</th><th>分类名称</th><th>操作</th>
            </tr>
            <!--i代表遍历时的下标-->
            <tr v-for="(c,i) in arr">
                <td>{{i+1}}</td>
                <td>{{c.name}}</td>
                <td><a href="#" @click="del(c.id)">删除</a></td>
            </tr>
        </table>
    </div>
</div>
</section>
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<!--引入vue框架-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<!--引入axios框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
let header_v = new Vue({
    el:"header",
    data:{
        user:""
    },
    created:function () {
        //发请求得到当前登录的用户对象
        axios.get("/checkLogin").then(function (response) {
            header_v.user = response.data;
            if (header_v.user==""){
                alert("请先登录!")
                location.href = "/login.html";
            }
        })
    },
    methods:{
        logout:function () {
            if (confirm("您确认退出登录吗?")){
                axios.get("/logout").then(function () {
                    location.href="/";//回到首页
                })
            }
        }
    }
})

    let section_v = new Vue({
        el:"section",
        data:{
            arr:[]
        },
        created:function () {
            //发请求获取所有的分类信息
            axios.get("/category/select").then(function (response) {
                section_v.arr = response.data;
            })
        },
        methods:{
            del:function (id) {
                if (!confirm("您确认删除吗?")){
                    return;
                }
                //发请求删除分类
                axios.get("/category/delete?id="+id).then(function () {
                    location.reload();//刷新页面
                })
            },
            add:function () {
                let name = prompt("请输入分类名称!");
                if (name==null){
                    return;
                }
                //发出异步请求添加分类
                axios.get("/category/add?name="+name).then(function () {
                   location.reload();
                })
            }
        }
    })
</script>
</body>
</html>